package cn.tunyun.service.impl;

import cn.tunyun.common.CommonResult;
import cn.tunyun.common.MD5Util;
import cn.tunyun.domain.User;
import cn.tunyun.query.BaseQuery;
import cn.tunyun.repository.UserRepository;
import cn.tunyun.service.LoginService;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
\
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private  UserRepository userRepository;


    @Override
    public void save(User user) {

    }

    @Override
    public void delete(Long aLong) {

    }

    @Override
    public User findOne(Long aLong) {
        return null;
    }

    @Override
    public List<User> findAll() {
        return null;
    }

    @Override
    public User findByUsername(String username, String pwd) {
        pwd = MD5Util.getSaltMD5(pwd);
        User user = userRepository.findByUsernameAndPassword(username, pwd);
        return user;
        }

    @Override
    public User findByUsername(String username) {
        return userRepository.findByUsername(username);
    }

    @Override
    public User register(String username, String password, String inviteCode) {
        //先查邀请吧是否存在
        Long aLong = chekInviteCode(inviteCode);
        if (aLong!=null){
            userRepository.save()
        }

        return null;
    }

    @Override
    public Long chekInviteCode(String invIteCode) {
        Long userByinvIteCode = userRepository.findUserByinvIteCode(invIteCode);
        return userByinvIteCode;
    }

}

